
package com.huizhan.web.dao;
 
import org.springframework.data.domain.*;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
import java.util.*;
import com.huizhan.web.model.*;


@Repository 
public interface AccountProjectRoleDao extends JpaRepository<AccountProjectRole,Long>
{
    /**
     * 根据用户ID获取项目角色集合
     * @param accountId 用户ID
     * @return 项目角色集合
     */
    List<AccountProjectRole> findByAccountId(String accountId);
    
    /**
     * 根据用户ID获取项目角色集合
     * @param accountId 用户ID
     * @return 项目角色集合
     */
    AccountProjectRole findByAccountIdAndProjectRoleId(String accountId,Long projectRoleId);
    
    /**
     * 根据用户ID获取项目角色集合
     * @param accountId 用户ID
     * @return 项目角色集合
     */
    AccountProjectRole findByAccountIdAndProjectId(String accountId,String projectId);
    
    /**
     * 分页查询用户项目角色集合
     * @param name 姓名
     * @param project 项目
     * @param role 角色
     * @param pageable 分页参数
     * @return 用户集合
     */
    @Query(
        value = "SELECT * FROM account_project_role"
            + " WHERE (name LIKE CONCAT('%',?1,'%') OR ?1  = '')"
            + " AND (project LIKE CONCAT('%',?2,'%') OR ?2  = '' )"
            + " AND (role LIKE CONCAT('%',?3,'%') OR ?3  = '' )",
        countQuery = "SELECT COUNT(1) FROM account"
            + " WHERE (name LIKE CONCAT('%',?1,'%') OR ?1  = '' )"
            + " AND (project LIKE CONCAT('%',?2,'%') OR ?2  = '' )"
            + " AND (role LIKE CONCAT('%',?3,'%') OR ?3  = '' )",
        nativeQuery = true
    )
    Page<AccountProjectRole> findByWhere(String name,String project,String role, Pageable  pageable);

}
